<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>赛诺菲_西南区 销量统计系统</title>
<%@ include file="../inc/fileHead.jsp"%>
</head>
<body class="easyui-layout">
	<div data-options="region:'center',border:false" style="height:100%;">
	<table id="dg" class="easyui-datagrid" title="库存调整"
		data-options="  
                iconCls: 'icon-edit',  
                singleSelect: true,  
                toolbar: '#tb',  
                onClickRow: onClickRow,
                onAfterEdit:onAfterEdit
            ">
		<thead>
			<tr>
				<th
					data-options="field:'productId',width:200,align:'center',hidden:'true'">
				</th>
				<th
					data-options="field:'customerId',width:200,align:'center',hidden:'true'">
				</th>
				<th data-options="field:'productName',width:200,align:'center'">
					产品</th>
				<th
					data-options="field:'amount',width:200,align:'right',editor:'numberbox'">
					库存</th>
			</tr>
		</thead>
	</table>
	<div id="tb" style="padding: 5px; height: auto">
		<div>
			<a href="javascript:void(0)" class="easyui-linkbutton"
				data-options="iconCls:'icon-save',plain:true" onclick="accept()">保存</a>
			客户级别 <input required="true" class="easyui-combobox"
				name="customerlevel"
				data-options="  
                    url:'BaseAction_selectGetCustomerLevel',  
                    valueField:'id',  
                    textField:'name',  
                    panelHeight:'auto',
                    onSelect:function(rec){
                    var url = 'BaseAction_selectGetCustomerNameByLevel?customerlevel='+rec.id; 
                     $('#customerid').combobox('reload', url); 
                    }
            " />
			客户名称 <input id="customerid" required="true" class="easyui-combobox"
				name="customerid"
				data-options="  
                    valueField:'id',  
                    textField:'name',  
                    panelHeight:'auto'  
            " />
			<a href="javascript:void(0);" class="easyui-linkbutton"
				iconCls="icon-search" onclick="searchInventory()">Search</a>
		</div>
	</div>
	<script type="text/javascript">
		var editIndex = undefined;
		
		function endEditing(){  
            if (editIndex == undefined){return true}  
            if ($('#dg').datagrid('validateRow', editIndex)){  
                return true;  
            } else {  
                return false;  
            }  
        }  
		function onClickRow(index){  
            if (editIndex != index){  
                if (endEditing()){  
                    $('#dg').datagrid('selectRow', index)  
                            .datagrid('beginEdit', index);  
                    $('#dg').datagrid('endEdit', editIndex); 
                    editIndex = index;  
                } else {  
                    $('#dg').datagrid('selectRow', editIndex);  
                }  
            }  
        } 
        
        function onAfterEdit(rowIndex, rowData, changes){
			$.ajax({
				type: "post",
            	url: "InventoryAction_updateByComposeId",
             	data: {qproductId:rowData.productId, qcustomerId:rowData.customerId,qamount:rowData.amount},
			});
        }
		
			function searchInventory(){
				$('#dg').datagrid({
                 url:'InventoryAction_findInventoryByCustomerId',  
				 queryParams: {
					customerId: $('#customerid').combobox("getValue")
				}
				});
			}
			function accept(){
			
			}
		</script>
		</div>
</body>
</html>
